import java.awt.Color;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;

public class Edge extends Line2D.Double {
	private static final long serialVersionUID = 7898774137611609467L;
	public static final int EDGE_WIDTH = 15;
	private Vertex m_from;
	private Vertex m_to;
	private boolean m_isPath = false;
	private int m_weigth = 0;
	private Color m_color = Color.BLACK;

	Edge(Vertex from, Vertex to, int weight) {
		super(from.getX(), from.getY(), to.getX(), to.getY());
		m_from = from;
		m_to = to;
		m_weigth = weight;
	}

	public int getCenterX() {
		int x1, x2;
		x1 = (int) this.getP1().getX();
		x2 = (int) this.getP2().getX();
		int x = (x1+x2)/2;
		if( (int) this.getP1().getY() >= (int) this.getP2().getY()){
			x = x+10;
		}
		else{
			x = x-10;
		}
		return x;
	}

	public int getCenterY() {
		int y1, y2;
		y1 = (int) this.getP1().getY();
		y2 = (int) this.getP2().getY();
		int y = (y1 + y2)/2;
		if( (int) this.getP1().getX() <= (int) this.getP2().getX()){
			y = y+10;
		}
		else{
			y = y-10;
		}
		return y;
	}

	public void free() {
		m_from.removeLink(this);
		m_to.removeLink(this);
	}

	public void refreshPos() {
		super.setLine(new Point2D.Double(m_from.getCenterX(),m_from.getCenterY()), new Point2D.Double(m_to.getCenterX(),m_to.getCenterY()));
	}

	public Vertex getFrom()	{
		return m_from;
	}

	public Vertex getTo() {
		return m_to;
	}

	public Color getColor() {
		return m_color;
	}

	public void setColor(Color color) {
		m_color = color;
	}

	public int getWeigth() {
		return m_weigth;
	}

	public void setWeigth(int m_weigth) {
		this.m_weigth = m_weigth;
	}

	public boolean isPath() {
		return m_isPath;
	}

	public void setIsPath(boolean isPath) {
		this.m_isPath = isPath;
		if(m_isPath == true) {
			m_color = Color.RED;
		}
		else {
			m_color = Color.BLACK;
		}
	}
}
